package com.yupfeg.test.base

import android.app.Application
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner

/**
 * 基类application
 * * 内部维护一个Application范围的[ViewModelStore]，
 * 可以此来借助 Application 来管理一个应用级的ViewModel，
 * @author yuPFeG
 * @date 2019/9/19
 */
open class BaseApplication : Application(), ViewModelStoreOwner{

    private lateinit var mAppViewModelStore: ViewModelStore

    companion object{
        lateinit var INSTANCE : BaseApplication
    }

    override fun onCreate() {
        super.onCreate()
        INSTANCE = this
        mAppViewModelStore = ViewModelStore()
    }

    /**ViewModelStoreOwner接口方法实现，表示其作用域范围在整个Application*/
    override fun getViewModelStore(): ViewModelStore {
        return mAppViewModelStore
    }

}